import { IGetAllUserReq, IGetAllUserRes, ISearchUserReq, ISearchUserRes, ReqApiUrls } from "@/headers/admin/reqs.h";
import { IAdminStore } from "@/headers/admin/store.h";
import { Store, ActionContext } from "vuex";
import { ActionBase, registerAll } from "../common";
import {apiAxios as axios} from '@/utils/axios'
import { pick } from "vant/lib/utils";
import { omit } from "lodash-es";

export class GetAllUserAction extends ActionBase<IAdminStore,IAdminStore,IGetAllUserReq,IGetAllUserRes>  {
    public async handle(store: Store<IAdminStore>, ctx: ActionContext<IAdminStore, IAdminStore>, payload: IGetAllUserReq): Promise<IGetAllUserRes> {
        const {data} = await axios.get<IGetAllUserRes>(ReqApiUrls.Users,{params:payload})
        return data;
    }
}

export class SearchUserAction extends ActionBase<IAdminStore,IAdminStore,ISearchUserReq,ISearchUserRes> {
    public async handle(store: Store<IAdminStore>, ctx: ActionContext<IAdminStore, IAdminStore>, payload: ISearchUserReq): Promise<ISearchUserRes> {
        const {data} = await axios.post<ISearchUserRes>(ReqApiUrls.UserSaerch,pick(payload,['where']),{params:omit(payload,'where')});
        return data;
    }
    
}

export function initUserAction(target:any) {
    registerAll(
        target,
        GetAllUserAction,
        SearchUserAction
    );
}